<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" type="shortcut icon" th:href="@{/img/favicon.ico}" />
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/css/global.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/css/discuss-detail.css}" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">

    <link rel="stylesheet" type="text/css" th:href="@{/editor-md/css/editormd.css}" />
    <title>Echo - 帖子详情</title>
</head>

<body>
    <div class="nk-container">

        <!-- 头部 -->
        <header class="bg-dark sticky-top" th:replace="index::header"></header>
        <!-- 内容 -->
        <div class="main">
            <!-- 帖子详情 -->
            <div class="container">
                <!-- 标题 -->
                <h5 class="mb-4">
                    <i class="bi bi-award" style="color: rgb(119, 84, 223)"></i>
                    <span th:utext="${singlePostVo.post.title}"></span>
                </h5>
                <!-- 作者 -->
                <div class="media pb-3 border-bottom">
                    <a th:href="@{/user/profile/{id}(id=${singlePostVo.user.id})}">
                        <img th:src="${singlePostVo.user.headerUrl}"
                            class="align-self-start mr-4 rounded-circle user-header" alt="用户头像">
                    </a>
                    <div class="media-body">
                        <a th:href="@{/user/profile/{id}(id=${singlePostVo.user.id})}">
                            <div class="mt-0 text-warning" th:utext="${singlePostVo.user.username}"></div>
                        </a>
                        <div class="text-muted mt-3">
                            发布于 <b
                                th:text="${T(com.qf.blog.commons.utils.DateTimeUtils).getRelativeTime(singlePostVo.post.createTime)}"></b>
                            <ul class="d-inline float-right">
                                <li class="d-inline ml-2">|</li>
                                <li class="d-inline ml-2"><a href="#replyform" class="text-primary">回帖 <i
                                            th:text="${commentVoList.size()}"></i></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- 正文 -->
                <div class="mt-4 mb-3 content" id="md-content">
                    <textarea style="display: none" th:utext="${singlePostVo.post.content}"></textarea>
                </div>
            </div>
            <!-- 回帖 -->
            <div class="container mt-3">
                <!-- 回帖数量 -->
                <div class="row">
                    <div class="col-8">
                        <h6><b class="square"></b> <i th:text="${commentVoList.size()}"></i>条回帖</h6>
                    </div>
                    <div class="col-4 text-right">
                        <a href="#replyform" class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;帖&nbsp;&nbsp;</a>
                    </div>
                </div>
                <!-- 回帖列表 -->
                <ul class="list-unstyled mt-4">
                    <li class="media pb-3 pt-3 mb-3 border-bottom" th:each="commVo:${commentVoList}">
                        <a th:href="@{/user/profile/{id}(id=${commVo.user.id})}">
                            <img th:src="${commVo.user.headerUrl}"
                                class="align-self-start mr-4 rounded-circle user-header" alt="用户头像">
                        </a>
                        <div class="media-body">
                            <div class="mt-0">
                                <a th:href="@{/user/profile/{id}(id=${commVo.user.id})}">
                                    <span class="font-size-12 text-success" th:utext="${commVo.user.username}"></span>
                                </a>
                            </div>
                            <div class="mt-2" th:utext="${commVo.commentEntity.content}"></div>
                            <div class="mt-4 text-muted font-size-12">
                                <span>发布于 <b
                                        th:utext="${T(com.qf.blog.commons.utils.DateTimeUtils).getRelativeTime(commVo.commentEntity.createTime)}"></b></span>
                                <ul class="d-inline float-right">
                                    <li class="d-inline ml-2">
                                        <a href="javascript:;"
                                            th:onclick="'handleLike({entityType:2,entityId:'+${commVo.commentEntity.id}+',likeStatus:'+${commVo.likeStatus}+',postId:'+${singlePostVo.post.id}+'})'"
                                            class="text-primary">
                                            <b th:text="${commVo.likeStatus ? '已赞' : '赞'}"></b>
                                            (<i th:text="${commVo.likeCount}"></i>)
                                        </a>
                                    </li>
                                    <li class="d-inline ml-2">|</li>
                                    <li class="d-inline ml-2">
                                        <a href="#" class="text-primary">回复(<i
                                                th:text="${commVo.replyList.size()}"></i>)</a>
                                    </li>
                                </ul>
                            </div>
                            <!-- 回复列表 -->
                            <ul class="list-unstyled mt-4 bg-gray p-3 font-size-12 text-muted">
                                <li class="pb-3 pt-3 mb-3 border-bottom" th:each="reply:${commVo.replyList}">
                                    <div>
                                        <span th:if="${reply !=null}">
                                            <a class="text-info" th:text="${reply.user.username}"
                                                th:href="@{|/account/info/${reply.user.id}|}"></a> 回复
                                            <a class="text-info" th:utext="${reply.targetname}"
                                                th:href="@{|/account/info/${reply.commentEntity.targetId}|}"></a>:&nbsp;&nbsp;
                                        </span>
                                        <span th:text="${reply.commentEntity.content}"></span>
                                    </div>
                                    <div class="mt-3">
                                        <span
                                            th:utext="${T(com.qf.blog.commons.utils.DateTimeUtils).getRelativeTime(reply.commentEntity.createTime)}"></span>
                                        <ul class="d-inline float-right">
                                            <li class="d-inline ml-2">
                                                <a href="javascript:;"
                                                    th:onclick="'handleLike({entityType:2,entityId:'+${reply.commentEntity.id}+',likeStatus:'+${reply.likeStatus}+',postId:'+${singlePostVo.post.id}+'})'"
                                                    class="text-primary">
                                                    <b th:text="${reply.likeStatus ? '已赞' : '赞'}"></b>
                                                    (<i th:text="${reply.likeCount}"></i>)
                                                </a>
                                            </li>
                                            <li class="d-inline ml-2">|</li>
                                            <li class="d-inline ml-2"><a th:href="|#huifu-${reply.commentEntity.id}|"
                                                    data-toggle="collapse" class="text-primary">回复</a></li>
                                        </ul>
                                        <!-- 回复 回复给回复 -->
                                        <div th:id="|huifu-${reply.commentEntity.id}|" class="mt-4 collapse">
                                            <form>
                                                <div>
                                                    <input type="text" class="input-size" name="content"
                                                        th:placeholder="|回复${reply.user.username}|" />
                                                    <input type="hidden" name="entityType" value="2">
                                                    <input type="hidden" name="entityId"
                                                        th:value="${commVo.commentEntity.id}">
                                                    <input type="hidden" name="targetId" th:value="${reply.user.id}">
                                                    <input type="hidden" name="userId"
                                                        th:value="${loginUser.userId}">
                                                    <input type="hidden" name="postId"
                                                        th:value="${singlePostVo.post.id}">
                                                </div>
                                                <div class="text-right mt-2">
                                                    <button type="button" onclick="handleReply.bind(this)()"
                                                        class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </li>

                                <!-- 回复 回复给评论 -->
                                <li class="pb-3 pt-3">
                                    <form>
                                        <div>
                                            <input type="text" class="input-size" name="content"
                                                placeholder="请输入你的观点" />
                                            <!-- 2代表是给人评论 -->
                                            <input type="hidden" name="entityType" value="2">
                                            <input type="hidden" name="entityId" th:value="${commVo.commentEntity.id}">
                                            <!-- 被评论的ID-->
                                            <input type="hidden" name="targetId" th:value="${commVo.user.id}">
                                            <!-- 被评论人的ID-->
                                            <input type="hidden" name="userId" th:value="${loginUser.userId}">
                                            <input type="hidden" name="postId" th:value="${singlePostVo.post.id}">
                                        </div>
                                        <div class="text-right mt-2">
                                            <button type="button" onclick="handleReply.bind(this)()"
                                                class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
                                        </div>
                                    </form>
                                </li>
                            </ul>
                        </div>
                    </li>

                </ul>
            </div>
            <!-- 评论 回复给帖子 -->
            <div class="container mt-3">
                <form class="replyform">
                    <p class="mt-3">
                        <textarea placeholder="在这里畅所欲言你的看法吧!" name="content"></textarea>
                        <input type="hidden" name="entityType" value="1">
                        <input type="hidden" name="entityId" th:value="${singlePostVo.post.id}">
                        <input type="hidden" name="targetId" th:value="${singlePostVo.user.id}">
                        <input type="hidden" name="userId" th:value="${loginUser.userId}">
                        <input type="hidden" name="postId" th:value="${singlePostVo.post.id}">
                    </p>
                    <p class="text-right">
                        <button type="button" onclick="handleReply.bind(this)()"
                            class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;帖&nbsp;&nbsp;
                        </button>
                    </p>
                </form>
            </div>
        </div>
        <!-- 尾部 -->
        <footer class="bg-dark" th:replace="index::footer"></footer>

    </div>
    <script th:src="@{/js/jquery-3.1.0.min.js}"></script>
    <script th:src="@{/js/popper.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/global.js}"></script>
    <script th:src="@{/js/httpUtils.js}"></script>
    <script th:src="@{/js/discuss.js}"></script>
    <script th:src="@{/js/logout.js}"></script>

    <script th:src="@{/editor-md/lib/marked.min.js}"></script>
    <script th:src="@{/editor-md/lib/prettify.min.js}"></script>
    <script th:src="@{/editor-md/lib/raphael.min.js}"></script>
    <script th:src="@{/editor-md/lib/underscore.min.js}"></script>
    <script th:src="@{/editor-md/lib/sequence-diagram.min.js}"></script>
    <script th:src="@{/editor-md/lib/flowchart.min.js}"></script>
    <script th:src="@{/editor-md/lib/jquery.flowchart.min.js}"></script>
    <script th:src="@{/editor-md/editormd.min.js}"></script>
    <script th:src="@{/js/like.js}"></script>
    <script type="text/javascript">
        var testEditor;
        $(function () {
            testEditor = editormd.markdownToHTML("md-content", {
                htmlDecode: "style,script,iframe",
                emoji: true,
                taskList: true,
                tex: true, // 默认不解析
                flowChart: true, // 默认不解析
                sequenceDiagram: true, // 默认不解析
                codeFold: true
            })
        })

        async function handleReply() {
            const formData = getFormData($(this.form));
            await $.post("/comment", formData);
            location.reload();
        }

    </script>
</body>

</html>
